import 'package:flutter/material.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:oramemo/common/styles/colors.dart';
import 'package:oramemo/entity/voice_record_entity.dart';
import 'package:oramemo/pages/transcription/files/controllers/transcriptio_files_logic.dart';

import 'ai_transcription_logic.dart';
import 'file_select_sheet.dart';

class FileMoveSheet extends StatelessWidget {
  FileMoveSheet({
    super.key,
    required this.data,
  });

  final VoiceRecordRows data;
  final TranscriptionFilesLogic fileLogic = Get.find();
  final AiTranscriptionLogic logic = Get.find();

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.fromLTRB(12.0, 10.0, 12.0, 0.0),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(12),
      ),
      child: Column(
        children: [
          const Text('Move to Folder'),
          Expanded(
            child: ListView(
              children: [
                for (final file in fileLogic.list)
                  FileSelectItem(
                    title: file.folderName ?? '',
                    onTap: () async {
                      if (data.id != null ||
                          file.id != null ||
                          data.voiceFolderId == file.id) {
                        bool res = await fileLogic.moveToFolder(
                            voiceId: data.id!.toString(), folderId: file.id!);
                        if (res && logic.fileLogic.currentFolder.value.id?.isNotEmpty == true) {
                          final list = logic.controller.voiceRecords;
                          list.removeWhere((element) => element.id == data.id);
                          logic.update();
                          // logic.requestData(page: 1);
                        }
                      }
                      Get.back();
                    },
                  ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
